package com.chrray.position.controller.web;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.chrray.position.domain.FdJobCategory;
import com.chrray.position.domain.FdJobSubcategory;
import com.chrray.position.pojo.dto.BaseIdDto;
import com.chrray.position.pojo.dto.web.FdJobCategoryExe;
import com.chrray.position.pojo.dto.web.FdJobSubcategoryExe;
import com.chrray.position.service.web.WFdJobCategoryService;
import com.chrray.position.service.web.WFdJobSubcategoryService;
import com.chrray.position.util.result.PageBean;
import com.chrray.position.util.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.chrray.position.util.result.ResponseResults.PAGE;
import static com.chrray.position.util.result.ResponseResults.success;

/**
 * 意见反馈表控制器
 *
 * @author lm
 * @since 1.0.1 2024-09-02
 */
@RestController
@RequestMapping("/api/web/jobSubcategory")
@Api(tags = "职位子类")
@AllArgsConstructor
public class WFdJobSubcategoryController {
    @Autowired
    private WFdJobSubcategoryService wFdJobSubcategoryService;

    @GetMapping("/pageList")
    @ApiOperation("列表")
    public ResponseResult<PageBean<FdJobSubcategory>> pageCheckList(FdJobSubcategoryExe dto) {
        return PAGE(wFdJobSubcategoryService.pageList(dto));
    }


    @GetMapping("/selectById")
    @ApiOperation("查询详情")
    @ApiResponses({
            @ApiResponse(code=200, message = "ok", response = FdJobSubcategory.class)
    })
    public ResponseResult<FdJobSubcategory> selectById(BaseIdDto dto){
        return  success(wFdJobSubcategoryService.getById(dto.getId()));
    }

    @GetMapping("/deletedById")
    @ApiOperation(" 删除")
    public ResponseResult deletedById(BaseIdDto dto){
        return  success(wFdJobSubcategoryService.removeById(dto.getId()));
    }

    @PostMapping("/updateById")
    @ApiOperation("编辑/是否热门职位")
    @ApiResponses({
            @ApiResponse(code=200, message = "ok", response = FdJobSubcategory.class)
    })
    public ResponseResult updateById(@RequestBody FdJobSubcategory entity){
        return  success(wFdJobSubcategoryService.updateById(entity));
    }

    @PostMapping("/save")
    @ApiOperation("添加")
    @ApiResponses({
            @ApiResponse(code=200, message = "ok", response = FdJobSubcategory.class)
    })
    public ResponseResult save(@RequestBody FdJobSubcategory entity){
        return  success(wFdJobSubcategoryService.save(entity));
    }

    @GetMapping("/listAll")
    @ApiOperation("列表bufenye")
    public ResponseResult<List<FdJobSubcategory>> listAll(FdJobSubcategory entity) {
        LambdaQueryWrapper<FdJobSubcategory> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(!ObjectUtils.isEmpty(entity.getName()), FdJobSubcategory::getName, entity.getName());
        queryWrapper.eq(!ObjectUtils.isEmpty(entity.getCategoryId()), FdJobSubcategory::getCategoryId, entity.getCategoryId());
        queryWrapper.orderByDesc(FdJobSubcategory::getCreatedTime);

        return success(wFdJobSubcategoryService.list(queryWrapper));
    }
}
